package org.lw.consumer.service.impl;

import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import io.seata.spring.annotation.GlobalTransactional;
import org.lw.consumer.feign.ProviderClient;
import org.lw.consumer.pojo.Order;
import org.lw.consumer.repositories.OrderRepository;
import org.lw.consumer.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/*@Transactional*/
@GlobalTransactional
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderRepository orderRepository;
    @Autowired
    private ProviderClient providerClient;
    @Override
    public String create(Order order) throws DegradeException {
        orderRepository.save(order); //保存订单
        return providerClient.deduct(order.getProductId(),order.getTotalAmount());//调用库存服务
        //System.out.println(1/0);//
    }
}